package com.company.笔试.二维数组查找;

public class Solution {
    public boolean Find(int target, int [][] array) {
        int rows = array.length;
        if(rows<=0) return false;
        int cols = array[0].length;
        if(cols<=0) return false;
        
        int row = 0;
        int col = cols-1;//右上角开始找
        
        while(col>=0&&row<rows){
            if(target == array[row][col]) return true;
            if(target < array[row][col]){
                col--;
            }else row++;
        }
        return false;
    }
}